package com.dkd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dkd.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.manage.domain.Node;
import com.dkd.manage.service.INodeService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 点位管理Controller
 *
 * @author QingMeng
 * @date 2024-11-16
 */
@Api(tags = "点位管理Controller")
@RestController
@RequestMapping("/manage/node")
public class NodeController extends BaseController
{
    @Autowired
    private INodeService nodeService;

    /**
     * 查询点位管理列表
     */
    @ApiOperation(value = "获取点位管理列表", notes = "根据条件查询点位管理列表")
    @PreAuthorize("@ss.hasPermi('manage:node:list')")
    @GetMapping("/list")
    public TableDataInfo list(
            @ApiParam(name = "node", value = "查询条件", required = false)
            Node node)
    {
        startPage();
        List<Node> list = nodeService.selectNodeList(node);
        return getDataTable(list);
    }

    /**
     * 导出点位管理列表
     */
    @ApiOperation(value = "导出点位管理列表", notes = "导出符合条件的点位管理列表为Excel文件")
    @PreAuthorize("@ss.hasPermi('manage:node:export')")
    @Log(title = "点位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(
            HttpServletResponse response,
            @ApiParam(name = "node", value = "导出条件", required = false)
            @RequestBody Node node)
    {
        List<Node> list = nodeService.selectNodeList(node);
        ExcelUtil<Node> util = new ExcelUtil<Node>(Node.class);
        util.exportExcel(response, list, "点位管理数据");
    }

    /**
     * 获取点位管理详细信息
     */
    @ApiOperation(value = "根据id获取点位管理详细信息", notes = "根据id获取点位管理的详细信息")
    @PreAuthorize("@ss.hasPermi('manage:node:query')")
    @GetMapping(value = "/{id}")
    public R<Node> getInfo(
            @ApiParam(name = "id", value = "点位管理ID", required = true)
            @PathVariable("id") Long id)
    {
        Node node = nodeService.selectNodeById(id);
        if (node != null){
            return R.ok(node);
        }else{
            return R.fail("点位管理id不存在,请重新输入");
        }
    }

    /**
     * 新增点位管理
     */
    @ApiOperation(value = "新增点位管理", notes = "新增一条点位管理记录")
    @PreAuthorize("@ss.hasPermi('manage:node:add')")
    @Log(title = "点位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(
            @ApiParam(name = "node", value = "新增的点位管理数据", required = true)
            @RequestBody Node node)
    {
        return R.toAjax(nodeService.insertNode(node));
    }

    /**
     * 修改点位管理
     */
    @ApiOperation(value = "修改点位管理", notes = "修改一条点位管理记录")
    @PreAuthorize("@ss.hasPermi('manage:node:edit')")
    @Log(title = "点位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(
            @ApiParam(name = "node", value = "修改的点位管理数据", required = true)
            @RequestBody Node node)
    {
        return R.toAjax(nodeService.updateNode(node));
    }

    /**
     * 删除点位管理
     */
    @ApiOperation(value = "删除点位管理", notes = "根据主键删除一条或多条点位管理记录")
    @PreAuthorize("@ss.hasPermi('manage:node:remove')")
    @Log(title = "点位管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(
            @ApiParam(name = "ids", value = "点位管理ID数组", required = true)
            @PathVariable Long[] ids)
    {
        return R.toAjax(nodeService.deleteNodeByIds(ids));
    }

}
